package com.haoshuang.zhouzhoubang.ui.page.account.login.account

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.UserBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class AccountLoginViewModel : BaseViewModel() {

    /**
     * 登录
     */
    val loginData = StatefulMutableLiveData<ResponseBean<UserBean>>()
    fun login(phone: String, password: String) = netRequest {
        start { loginData.value = StateData.Loading }
        request { ApiRepo.login(phone, "1", password)  }
        success { loginData.value = StateData.Success(it) }
        error { code, msg ->
            loginData.value = StateData.Error(code, msg)
        }
    }


}